package com.zcaxer.roomwordsample.data

import androidx.annotation.WorkerThread
import androidx.lifecycle.LiveData

class BuildingRepository(private val buildingDao: BuildingDao) {
    val buildings: LiveData<List<Building>> = buildingDao.getBuildings()

    suspend fun updateBuilding(building: Building) = buildingDao.updateBuilding(building)
    @WorkerThread
    suspend fun updateBuildingWorkers(buildingId: Int, workers: Int) = buildingDao.updateWorkers(buildingId, workers)
    @WorkerThread
    suspend fun updateBuildingReserve(buildingId: Int, reserve: Int) = buildingDao.updateReserve(buildingId, reserve)

    companion object {

        // For Singleton instantiation
        @Volatile private var instance: BuildingRepository? = null

        fun getInstance(buildingDao: BuildingDao) =
            instance ?: synchronized(this) {
                instance ?: BuildingRepository(buildingDao).also { instance = it }
            }
    }


}